package baptizeattribute.baptize;

import baptizeattribute.dao.AttributeDao;
import baptizeattribute.dao.ConfigDao;
import baptizeattribute.dao.ItemDao;
import baptizeattribute.data.Data;
import baptizeattribute.event.Cmd;
import baptizeattribute.event.InvClick;
import baptizeattribute.event.InventoryClose;
import baptizeattribute.event.PlayerQuit;
import baptizeattribute.inventory.Inv;
import baptizeattribute.resource.PathConfiguration;
import baptizeattribute.utils.IOUtil;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.HashMap;

public final class Baptize extends JavaPlugin {
    private static Baptize PluginMain;
    @Override
    public void onEnable() {
        PluginMain = this;
        saveResource("config.yml",false);
        if (!IOUtil.fileExists(PathConfiguration.Items)) {
            new ItemDao().setItem();
        }
        setData();
        setlins();
        getServer().getConsoleSender().sendMessage("§d==========§e洗炼系统§d==========");
        getServer().getConsoleSender().sendMessage("        §a插件加载成功");
        getServer().getConsoleSender().sendMessage("§d============================");
    }

    /**
     * 初始化
     */
    public static void setData(){
        Data.item = new ItemDao().getItem();
        Data.config = new ConfigDao().getConfigure();
        Data.AttributeList = new AttributeDao().getAttributeList();
        Inv.playerIv = new HashMap<>();
        Data.guiFlag = new HashMap<>();
    }

    /**
     * 注册
     */
    public void setlins(){
        Bukkit.getPluginCommand("xl").setExecutor(new Cmd());
        Bukkit.getPluginManager().registerEvents(new InvClick(), this);
        Bukkit.getPluginManager().registerEvents(new InventoryClose(), this);
//        Bukkit.getPluginManager().registerEvents(new PlayerQuit(), this);
    }

    public static Baptize getMain(){
        return PluginMain;
    }
}
